<template>
  <a-spin :spinning="confirmLoading">
    <div v-if="model.authStatus=='3'" class="revisedContent">驳回原因：请上传清晰的身份证</div>
    <h3 class="title">基本信息</h3>
     <a-form-model>
    <a-form-model-item label="认证类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="authType">
        <a-radio-group v-model="authType" @change="onChangeAuthType">
                <a-radio value="0" :disabled="initAuthType=='1'?true:false">个人认证</a-radio>
                <a-radio value="1">企业认证</a-radio>
              </a-radio-group>               
      </a-form-model-item>
      </a-form-model>
    <base-settle-org-personal-auth v-if="authType=='0'" ref="BaseSettleOrgPersonalAuth" :model="model" @ok="submitCallback" @loadingCallback="loadingCallback"></base-settle-org-personal-auth>
    <base-settlement-company-auth v-if="authType=='1'" ref="BaseSettlementCompanyAuth" :companyModel="companyModel" @ok="submitCallback" @loadingCallback="loadingCallback"></base-settlement-company-auth>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
// base-settle-org-personal-auth
// import BaseSettleOrgPersonalAuth from '../modules/BaseSettlementOrgUserForm.vue'
import BaseSettlementCompanyAuth from '../modules/BaseSettlementCompanyAuth.vue'
import BaseSettleOrgPersonalAuth from '../BaseSettleOrgPersonalAuth.vue'
export default {
  name: 'BaseSettlementOrgUserForm',
  components: {BaseSettlementCompanyAuth, BaseSettleOrgPersonalAuth},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
 
  },
  data() {
    return {
      authType:'0',
      model: {
        authType:'0',
        orgName:'',
      },
      companyModel:{
        authType:'1',
        izSamePerson:'1',  
      },
      initAuthType:'0',
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      labelColIdCard: {
        xs: { span: 24 },
        sm: { span: 10 },
      },
      wrapperColIdCard: {
        xs: { span: 24 },
        sm: { span: 14 },
      },
      confirmLoading: false,
      url: {
        // add: '/finance/baseSettlementOrgUser/add',
        commit: '/finance/baseSettlementOrgAuth/commit',
        queryById: '/finance/baseSettlementOrgAuth/queryById',  //通过id查询组织认证信息
      },
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) { 
      //this.model = Object.assign({}, record)
      // this.model.id=record.id
      this.getBaseSettlementOrgAuth(record)
      this.visible = true
    },
    // validateMobile(rule, value, callback) {
    //   if (!value || new RegExp(/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/).test(value)) {
    //     callback()
    //   } else {
    //     callback('手机号码格式不正确!')
    //   }
    // },
    // validateIdCard(rule, value, callback) {
    //     if (!value || new RegExp(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/).test(value)) {
    //       callback();
    //     } else {
    //       callback("您的身份证号码格式不正确!");
    //     }
    //   },
       submitCallback(){       
        this.$emit('ok');
        this.visible = false;
      },
    //获取认证信息
    getBaseSettlementOrgAuth(record){
      const that=this
      getAction(that.url.queryById, {id: record.id})
         .then(res=>{         
          if(res.success){
            res.result.authType=res.result.authType?res.result.authType:'0'
            that.authType=res.result.authType
            if(that.authType=='0'){
               that.model=res.result
             that.model.orgName=record.name
            }else{
              that.companyModel =res.result
             that.companyModel.orgName=record.name
            }
             that.initAuthType=res.result.authType?res.result.authType:'0'
          }else{
            that.$message.warning(res.result)
          }
         })
    },
    //切换认证类型
    onChangeAuthType(e){
      if(e.target.value=='1'){
         this.companyModel ={
            id:this.model.id,
            authType:'1',
            orgName:this.model.orgName,
            izSamePerson:'1',
           }    
      }

    },
    submitForm() {
      const that = this
        //个人：1,2     //企业认证:是同一人:1,2  不是同一人：1,2，3,4
      // 触发表单验证
       that.confirmLoading = true     
      if(that.authType=='0'){
           that.$refs.BaseSettleOrgPersonalAuth.submitForm()
      }else if(that.authType=='1'){
          that.$refs.BaseSettlementCompanyAuth.submitForm()
      }
     
     
    },
   
  },
    // watch:{
    //    'authType':{
    //        handler(newValue,oldValue){
    //          const that=this
    //         const d=this.initAuthType
    //          if(newValue !== oldValue){
    //             if(this.initAuthType=='0'){
    //                  that.companyModel ={
    //                   id:that.model.id,
    //                   authType:'1',
    //                   orgName:that.model.orgName,
    //                   izSamePerson:'1',
    //                  }    
    //             }
    //          }
    //        },
    //        deep:true
    //    }
    //  }
}
</script>
<style scoped>
.title {
  font-weight: bold;
  margin-left: 3%;
}
.operating {
  padding-right: 30px;
}
.revisedContent {
  margin-bottom: 15px;
  width: 100%;
  background: #fef1e1;
  color: #f59a23;
  font-size: 12px;
  padding: 10px 15px;
}
.idCardImgBack {
  display: inline-block;
  float: left;
}
.idCardImgBackdemo {
  display: inline-block;
  width: 102px;
  height: 103px;
  border: 1px dashed #d9d9d9;
  border-radius: 4px;
  text-align: center;
  margin-left: 15px;
  padding: 5px 0;
}
</style>